//
//  UploadSendVC.m
//  Inforcollection
//
//  Created by ocean on 16/10/26.
//  Copyright © 2016年 oceansoft.liw. All rights reserved.
//

#import "UploadSendVC.h"
#import "NotAndUploadCell.h"
#import "UserData.h"
#import "SDImageCache.h"
#import "UtilObject.h"
@interface UploadSendVC ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView*DiDUploadTable;
    NSMutableArray*SenderArray;
    UIView*noDataView;
    NSMutableArray*MagersData;
    long pageIndex;
}
@end

@implementation UploadSendVC

- (void)viewDidLoad {
    MagersData=[NSMutableArray array];
    pageIndex=1;
    [super viewDidLoad];
    [self getDiduploadSenderList];
    SenderArray=[NSMutableArray array];
    [self setNaviBarTitle:@"已上传寄件单"];
    [self setNavBarColor:APPNavibackColor];
    [self setNoTiploadTableFrame];
}
-(void)setNoTiploadTableFrame{
    
    DiDUploadTable=[[UITableView alloc]initWithFrame:CGRectMake(0, APPNaviHeight, ScreenWidth, ScreenHeight-APPNaviHeight-45) style:UITableViewStyleGrouped];
    DiDUploadTable.delegate=self;
    DiDUploadTable.dataSource=self;
    [self setupRefresh:DiDUploadTable type:2];
    
    [self.view addSubview:DiDUploadTable];
    noDataView = [UtilObject getNodataTipView];
    [DiDUploadTable addSubview:noDataView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return MagersData.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 105;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NotAndUploadCell*Cell=[[[NSBundle mainBundle]loadNibNamed:@"NotAndUploadCell" owner:nil options:nil] firstObject];
    if (MagersData.count!=0) {
    NSDictionary*Diction=MagersData[indexPath.section];
    NSArray*array=Diction[@"goodsPicUrlFdfs"];
    if (array.count!=0) {
        NSString*fileURL=[BaseImageURl stringByAppendingFormat:@"%@",array[0]];
        
        [Cell.IconImage setImageWithURL:[NSURL URLWithString:fileURL]
                       placeholderImage:[UIImage imageNamed:@"DiduploadPlicehoder"]];
    }else{
        
        [Cell.IconImage setImageWithURL:[NSURL URLWithString:@""]
                       placeholderImage:[UIImage imageNamed:@"DiduploadPlicehoder"]];
    }
    Cell.OrdNumLable.text=Diction[@"orderNo"];
    Cell.NameLab.text=Diction[@"senderName"];
    Cell.TelpLable.text=Diction[@"senderPhone"];
    Cell.AdressLable.text=Diction[@"senderAddressAuto"];
    Cell.TimeLable.text=Diction[@"createTime"];
    
    if ([Diction[@"isUploadPic"] integerValue]==0) {
        Cell.StaticLab.text=@"未完成";
    }else{
        Cell.StaticLab.backgroundColor=AppNavColor;
        Cell.StaticLab.text=@"已完成";
   }
  }
    return Cell;
}
-(void)getDiduploadSenderList{
   
    NSMutableDictionary*Dict=[NSMutableDictionary dictionary];
    [Dict setObject:[UserData shareUserData].userModel.dbId forKey:@"reveiverId"];

    [Dict setValue:[NSString stringWithFormat:@"%li",(long)pageIndex] forKey:@"pageIndex"];
    [Dict setValue:@"10" forKey:@"pageSize"];
    [MBProgressHUD showMessag:@"正在加载" toView:SharedApplication.keyWindow];
 

    [[HttpAPI shareHttpAPI]getDiduploadSenderList:Dict CallBack:^(NSDictionary *receivedData) {
        [MBProgressHUD hideAllHUDsForView:SharedApplication.keyWindow animated:YES];
        if (receivedData==nil) {
            [MBProgressHUD showError:@"网络错误" toView:self.view];
        }else{
            if ([receivedData[@"status"] integerValue]==1) {
                NSDictionary*dictarray=receivedData[@"data"];
                SenderArray=dictarray[@"data"];
                [MagersData addObjectsFromArray:SenderArray];
                if (MagersData.count==0)
                {
                    [DiDUploadTable addSubview:noDataView];
                }else
                {
                    [noDataView removeFromSuperview];
                }
                [DiDUploadTable reloadData];
        }
    }
        [DiDUploadTable headerEndRefreshing];
        [DiDUploadTable footerEndRefreshing];
 }];
}

-(BOOL)hidesBottomBarWhenPushed{
    
    return YES;
}
-(void)headerRereshing
{
    
    [MagersData removeAllObjects];
    pageIndex=1;
    [self getDiduploadSenderList];
    
}

-(void)footerRereshing
{
    
    pageIndex=pageIndex+1;
    [self getDiduploadSenderList];
    
}
@end
